﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FB.DataAccess;
using FB.Utilities;

namespace FB.Bussiness
{
    public class Video_CategoryBO
    {
        public IEnumerable<Video_Category> GetAllVideo_Category()
        {
            Video_CategoryDAO _dao = new Video_CategoryDAO();
            return _dao.GetAllVideo_Category();
        }
        public Video_Category GetVideo_CategoryById(Guid id)
        {
            Video_CategoryDAO _dao = new Video_CategoryDAO();
            return _dao.GetVideo_CategoryByID(id);
        }
        public bool UpdateVideo_Category(Video_Category inVideo_Category)
        {
            Video_CategoryDAO _dao = new Video_CategoryDAO();
            return _dao.UpdateVideo_Category(inVideo_Category);
        }
        public bool InsertVideo_Category(Video_Category inVideo_Category)
        {
            Video_CategoryDAO _dao = new Video_CategoryDAO();
            return _dao.InsertVideo_Category(inVideo_Category);
        }

        public ReturnValue<bool> DelVideo_Category(Guid id)
        {
            Video_CategoryDAO _dao = new Video_CategoryDAO();
            return _dao.DelVideo_Category(id);
        }

        public List<Guid> GetCategoryIDOfVideo(Guid videoID)
        {
            List<Guid> result = new List<Guid>();
            Video_CategoryDAO _dao = new Video_CategoryDAO();
            IEnumerable<Video_Category> listCate = _dao.GetCategoryIDOfVideo(videoID).ToList();
            foreach (Video_Category item in listCate)
            {
                result.Add(item.IDCategory);
            }
            return result;
        }


        public void UpdateCategoryOfVideo(Guid videoID, List<Guid> videoCatList)
        {
            // Delete all category of this Video
            Video_CategoryDAO _dao = new Video_CategoryDAO();
            _dao.DeleteVideo_CategoryByVideoID(videoID);
            // Add new category for this Video
            foreach (Guid cate in videoCatList)
            {
                Video_Category newVideo_Cat = new Video_Category();
                newVideo_Cat.ID = Guid.NewGuid();
                newVideo_Cat.IDCategory = cate;
                newVideo_Cat.IDVideo = videoID;
                _dao.InsertVideo_Category(newVideo_Cat);
            }
        }
    }
}
